<?php
/**
 * 展示选手个人信息
 * @param [type] $playerInfo_result  [选手信息查询集]
 */
function MyInfoShow($playerInfo_result){
    $user_uid       = $playerInfo_result['uid'];
    $user_name      = $playerInfo_result['name'];
    $user_nickname  = $playerInfo_result['nickname'];
    $user_skilled   = $playerInfo_result['skilled'];
    $user_point     = $playerInfo_result['totalpoint'];
    $user_email     = $playerInfo_result['email'];
    echo <<<MyStart
        <link href="/afctf/css/player.css" rel="stylesheet" type="text/css" media="all"/>
            <div class="layui-container">
                <div class="layui-row layui-col-space20">
                    <!-- basic-info-box -->
                    <div class="layui-col-md12">
                        <div class="panel">
                            <blockquote class="layui-elem-quote">基本信息</blockquote>
                            <div class="panel-body layui-col-md12">
                                <div class="layui-col-md6" style="margin-top:2%;padding-left:10%;">
                                    <div class="info-table" style="margin-top:20px;">
                                        <dl class="info-dl">
                                            <dt>
                                                <label>学号:</label>
                                            </dt>
                                            <dd class="viewModule">
                                                <span class="info-text" id="username">$user_uid</span>
                                            </dd>
                                        </dl>
                                        <dl class="info-dl">
                                            <dt>
                                                <label>姓名:</label>
                                            </dt>
                                            <dd class="viewModule">
                                                <span class="info-text" id="username">$user_name</span>
                                            </dd>
                                        </dl>
                                        <dl class="info-dl">
                                            <dt>
                                                <label for="">昵称:</label>
                                            </dt>
                                            <dd class="viewModule">
                                                <span class="info-text">$user_nickname</span>
                                            </dd>
                                        </dl>
                                        <dl class="info-dl">
                                            <dt>
                                                <label for="">强项:</label>
                                            </dt>
                                            <dd class="viewModule">
                                                <span class="info-text">$user_skilled</span>
                                            </dd>
                                        </dl>
                                        <dl class="info-dl">
                                            <dt>
                                                <label for="">得分:</label>
                                            </dt>
                                            <dd class="viewModule">
                                                <span class="info-text">$user_point</span>
                                            </dd>
                                        </dl>
                                        <dl class="info-dl">
                                            <dt>
                                                <label for="">邮箱:</label>
                                            </dt>
                                            <dd class="viewModule">
                                                <span class="info-text">$user_email</span>
                                            </dd>
                                        </dl>
                                        <div id="infochange">
                                            <button class="layui-btn" onclick="infochange('members/infochange.php');">修改个人信息 / 密码</button>
                                        </div>
                                        <script type="text/javascript" src="../layui/layui.all.js"></script>
                                        <script>
                                        function infochange(url) {
                                            layer.open({
                                            type: 2,
                                            shadeClose:true,
                                            title: "修改个人信息",
                                            content: url,
                                            area: [window.innerWidth * 1.5 / 3 + "px", window.innerHeight * 26 / 30 + "px"],
                                            });
                                        }
                                        </script>
                                    </div>
                                </div>
                                <div id="charts" class="layui-col-md6" style="height:300px"></div>
                            </div>
                            
                        </div>

                    </div>
MyStart;
}
/**
 * 查询选手答题历史记录
 * @param [type] $playerHistory  [答题记录查询集]
 * @param [type] $historyCount [记录条数]
 * @thinking
 *     1.根据用户名查询答题记录表，获取每道题答题情况(分值)，根据分数判断是否答对
 *     2.按题目类型对History数组进行排序
 *     3.将结果展示到个人信息处
 * @修改：由于基本信息处需要读取分数信息，故把数据库操作放在my.php中
 */
function MyHisShow($playerHistory,$historyCount){
    $No = 0;
    // 3.将结果展示到个人信息处
    echo <<<HistoryStart
        <div class="layui-col-md12">
                <blockquote class="layui-elem-quote">解题历史</blockquote>
                <div>
                    <table border="1" class="layui-table">
                        <thead>
                            <tr align="center">
                                <th>序号</th>
                                <th>题目分类</th>
                                <th>题目标题</th>
                                <th>解出时间</th>
                                <th>题目分值</th>
                            </tr>
                        </thead>
HistoryStart;
    if($historyCount === 0){
        echo <<<EOT
        <tr align="center">
            <td colspan="5">暂无数据</td>
        </tr>
EOT;
    }
    else{
        for($i = 0;$i < $historyCount;$i++){
            $No = $i + 1;
            $type = $playerHistory[$i]['type'];
            $title = $playerHistory[$i]['title'];
            $submit_time = $playerHistory[$i]['submit_time'];
            $point = $playerHistory[$i]['point'];
            echo <<<History
                        <tbody>
                            <tr align="center">
                            <td>$No</td>
                            <td>$type</td>
                            <td>$title</td>
                            <td>$submit_time</td>
                            <td>$point</td>
                          </tr>
                        </tbody>
History;
        }
    }
    echo <<<HistoryEnd
                        </table>
                    </div>
                </div>
            </div>
        </div>
HistoryEnd;
}
/**
 * 用户四维能力展示
 * @param [type] $playerTypePoint_result     [选手思维能力查询集]
 */
function MyAbilityShow($playerTypePoint){
    $Param = ["1","0.7","0.4","0.1"];
    $count = 0;
    $maximum = 0;
    $Crypto_point  = $playerTypePoint['Crypto_point'];
    $Misc_point    = $playerTypePoint['Misc_point'];
    $Reverse_point = $playerTypePoint['Reverse_point'];
    $Web_point     = $playerTypePoint['Web_point'];

    $typeParam['Crypto_param'] = $playerTypePoint['Crypto_point'];
    $typeParam['Misc_param'] = $playerTypePoint['Misc_point'];
    $typeParam['Reverse_param'] = $playerTypePoint['Reverse_point'];
    $typeParam['Web_param'] = $playerTypePoint['Web_point'];
    arsort($typeParam);

    foreach($typeParam as $key=>$value){
        if($count === 0){
            $maximum = $value;
        }
        $$key = $Param[$count];
        $count = $count + 1;
    }
    
    $maximum = $maximum * 1.3;
    if($maximum == 0){
        $maximum = 100;
    }

    echo <<<JS
    <script type="text/javascript" src="/afctf/layui/layui.all.js"></script>
    <script type="text/javascript">
        var dom = document.getElementById("charts");
        var myChart = echarts.init(dom);
        var app = {};
        option = null;
        option = {
            tooltip: {},
            radar: {
                // shape: 'circle',
                name: {
                    textStyle: {
                        color: '#fff',
                        backgroundColor: '#1F9788',
                        borderRadius: 2,
                        padding: [3, 5, 3, 7]
                   }
                },
                indicator: [
                   { name: 'Web', max: $maximum},
                   { name: 'Reverse', max: $maximum},
                   { name: 'Crypto', max: $maximum},
                   { name: 'Misc', max: $maximum},
                ]
            },
            series: [{
                type: 'radar',
                // areaStyle: {normal: {}},
                itemStyle: {
                    normal: {
                        areaStyle: {
                            type: 'default'
                        }
                    }
                },
                color: {
                    type: 'linear',
                    x: $Reverse_param,//Reverse
                    y: $Web_param,//Web
                    x2: $Misc_param,//Misc
                    y2: $Crypto_param,//Crypto
                    colorStops: [{
                        offset: 0, color: 'rgb(240,127,127,0.2)' // 0% 处的颜色
                    }, {
                        offset: 1, color: 'red' // 100% 处的颜色
                    }],
                    globalCoord: false // 缺省为 false
                },
                data : [
                    {
                        value : [$Web_point, $Reverse_point, $Crypto_point, $Misc_point],
                        name : '个人得分情况'
                    }
                ]
            }]
        };;
        if (option && typeof option === "object") {
            myChart.setOption(option, true);
        }
           </script>
    </div>
JS;
}
?>
<?php
/**
* Author: Porlock
* Link: www.porlockz.com
* Date: 2018-04-19 15:32:28
* Last Modified time: 
* Use：显示选手信息【选手个人信息，五维图，解题历史】
* 1.根据uid获取选手答题情况，存储在一个数组中传入函数进行展示
* 2.将获取的成绩按类别分类（按分数降序排序）
* 3.根据uid读取选手信息，传入函数进行展示
*/
require_once ('includes/lib/func_rightCtrl.php');
// 权限控制
player_rightCtrl();
$uid = $_SESSION['uid'];
/* **********************用户答题成绩数据获取*********************** */
/* count                答对题目计数器
 * web_point            Web题目得分
 * reverse_point        Reverse题目得分
 * misc_point           Misc题目得分
 * crypto_point         Crypto题目得分
 */
//1.根据uid获取选手答题情况，存储在一个数组中传入函数进行展示
$playerHistory_query = "SELECT `title`,`submit_time`,`type`,`point` FROM `solved_situation` WHERE `uid` = :uid ORDER BY `type`";
$sth_playerHistory   = $dbh->prepare($playerHistory_query);
$sth_playerHistory   -> bindParam(":uid",$uid);
$sth_playerHistory   -> execute();
$historyCount        = $sth_playerHistory->rowCount();
$playerHistory       = $sth_playerHistory->fetchALL();
//2.将获取的成绩按类别分类（按分数降序排序）
    // 初始化四维能力数组
$playerTypePoint = array("Crypto_point"=>"","Misc_point"=>"","Reverse_point"=>"","Web_point"=>"");
    // 按Crypto Misc Reverse Web 的顺序检索
$playerTypePoint_query = "SELECT `type`,sum(`point`) AS `sumPoint` FROM `solved_situation` WHERE `uid` = :uid GROUP BY `type` ORDER BY `type` ASC";
$sth_playerTypePoint   = $dbh->prepare($playerTypePoint_query);
$sth_playerTypePoint   -> bindParam(":uid",$uid);
$sth_playerTypePoint   -> execute();
$playerTypePoint_result = $sth_playerTypePoint->fetchAll();
    // 如果有一个类型或以上的问题未解答过，则会出现空的情况，进行处理
for($i = 0;$i < 4;$i++){
        if(@$playerTypePoint_result[$i]["type"] == 'Crypto'){
            $playerTypePoint['Crypto_point'] = @$playerTypePoint_result[$i]["sumPoint"];
            continue;
        }elseif (@$playerTypePoint_result[$i]["type"] == 'Misc') {
            $playerTypePoint['Misc_point'] = @$playerTypePoint_result[$i]["sumPoint"];
            continue;
        }elseif (@$playerTypePoint_result[$i]["type"] == 'Reverse') {
            $playerTypePoint['Reverse_point'] = @$playerTypePoint_result[$i]["sumPoint"];
            continue;
        }elseif (@$playerTypePoint_result[$i]["type"] == 'Web') {
            $playerTypePoint['Web_point'] = @$playerTypePoint_result[$i]["sumPoint"];
            continue;
        }
    }
foreach($playerTypePoint as $key=>$value){
    if($value == NULL){
        $playerTypePoint[$key] = 0;
    }
}
    //对处理好的数组进行排序
arsort($playerTypePoint);
// //3.将强项存入用户信息表user
// $playerSkilled_update   = "UPDATE `user` SET `skilled` = :skilled WHERE `uid` = :uid";
// $sth_playerSkilled      = $dbh->prepare($playerSkilled_update);
// $sth_playerSkilled      ->bindParam(":skilled",$playerSkilled);
// $sth_playerSkilled      ->bindParam(":uid",$uid);
// $sth_playerSkilled      ->execute();
//3.根据uid读取选手信息，传入函数进行展示
$playerInfo_query       = "SELECT `uid`,`name`,`nickname`,`email`,`skilled`,`totalpoint` FROM `user` WHERE `uid` = :uid";
$sth_playerInfo         = $dbh->prepare($playerInfo_query);
$sth_playerInfo         ->bindParam(":uid",$uid);
$sth_playerInfo         ->execute();
$playerInfo_result      = $sth_playerInfo->fetch();
/* **********************展示用户个人信息*********************** */
MyInfoShow($playerInfo_result);
/* **********************展示用户历史答题*********************** */
MyHisShow($playerHistory,$historyCount);
/* ********************展示用户四维能力图*********************** */
MyAbilityShow($playerTypePoint);
?>